package com.live.stamp.base.validation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.container.core.common.BusinessException;

/**
 * 自然数验证处理器 包括正整数 + 0
 */
public class NaturalNumberHandle extends ParamHandler {
    private static final Logger logger = LoggerFactory.getLogger(NaturalNumberHandle.class);

    @Override
    protected ValidationEnum getParamHandleType() {
        return ValidationEnum.NATURAL_NUM;
    }

    @Override
    protected void echo(String paramName, Object param) {
        Integer p = (Integer)param;
        if(p == null){
            logger.error("NaturalNumberHandle class -> param:{} is null!", paramName);
            throw new BusinessException(String.format("数字%s不存在", paramName));
        }
        if(p < 0){
            logger.error("NaturalNumberHandle class -> NaturalNumber:{} less than zero!", p);
            throw new BusinessException(String.format("数字%s小于0", paramName));
        }
    }
}
